#include "CCSkeletalAnimation.h"
#include "CCSkeletalSprite.h"

NS_CC_BEGIN

CCSkeletalAnimation::CCSkeletalAnimation() :
m_duration(0) {
}

CCSkeletalAnimation::~CCSkeletalAnimation() {
	for(auto it:m_transList) {
		it->release();
	}
}

CCSkeletalAnimation* CCSkeletalAnimation::create() {
	CCSkeletalAnimation* a = new CCSkeletalAnimation();
	return (CCSkeletalAnimation*)a->autorelease();
}

void CCSkeletalAnimation::addTransform(CCTransform* t) {
	m_transList.push_back(t);
	t->retain();
}

void CCSkeletalAnimation::addEventsKeyFrame(const EventsKeyFrame &kf) {
    m_ekfList.push_back(kf);
}

void CCSkeletalAnimation::applyTo(CCSkeletalSprite *owner, float frameTime, float delta) {
    float curTime=frameTime+delta;
    for (auto &it:m_ekfList) {
        if (it.time<curTime) {
            if (it.time>=frameTime) {
                owner->handleEvents(&it);
            }
        }
        else {
            break;
        }
    }
}

NS_CC_END